package org.saratogaschools.edd.firefighter.client.activity;

import org.saratogaschools.edd.firefighter.client.ClientFactory;
import org.saratogaschools.edd.firefighter.client.place.AddDepartmentPlace;
import org.saratogaschools.edd.firefighter.client.place.AddFirePlace;
import org.saratogaschools.edd.firefighter.client.place.EnterNamePlace;
import org.saratogaschools.edd.firefighter.client.place.FireListPlace;
import org.saratogaschools.edd.firefighter.client.place.FirePlace;
import org.saratogaschools.edd.firefighter.client.place.SelectDepartmentPlace;
import org.saratogaschools.edd.firefighter.client.place.SelectRolePlace;
import org.saratogaschools.edd.firefighter.shared.model.FireFighter;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

public class ActivityMapperImpl implements ActivityMapper {

	private ClientFactory clientFactory;

	public ActivityMapperImpl(ClientFactory clientFactory) {
		this.clientFactory = clientFactory;
	}

	@Override
	public Activity getActivity(Place place) {
		if (place instanceof EnterNamePlace) {
			return new EnterNameActivity((EnterNamePlace)place, clientFactory);
		}
		else if (place instanceof SelectDepartmentPlace) {
			return new SelectDepartmentActivity((SelectDepartmentPlace)place, clientFactory);
		}
		else if (place instanceof AddDepartmentPlace) {
			return new AddDepartmentActivity((AddDepartmentPlace)place,clientFactory);
		}
		else if (place instanceof SelectRolePlace) {
			return new SelectRoleActivity((SelectRolePlace)place,clientFactory);
		}
		else if (place instanceof FireListPlace) {
			return new FireListActivity((FireListPlace)place,clientFactory);
		}
		else if (place instanceof AddFirePlace) {
			return new AddFireActivity((AddFirePlace)place,clientFactory);
		}
		else if (place instanceof FirePlace) {
			FireFighter fighter = ((FirePlace)place).getFighter();
			if (fighter.canCheckInToFires()) {
				return new CheckInActivity((FirePlace)place,clientFactory);
			}
			else {
				return new ManageFireActivity((FirePlace)place,clientFactory);
			}
		}
		else {
			throw new IllegalArgumentException("Place " + place.toString()
					+ " does not map to an Activity");
		}
	}

}
